<?php

	class product_detail_DAO extends CI_Model{

		public function __construct(){
			parent::__construct();
			$this->load->database();
		}

		public function getAll(){
			$query = $this->db->get("product_detail");
			return $query->result_array();
		}
		
		public function search($product_code_id, $code){
			$this->db->where('product_code_id', $product_code_id);
			$this->db->where('code', $code);
			$query = $this->db->get("product_detail");
			if($query->num_rows() == 1){
				return $query->row_array();
			} else{
				return null;
			}
		}
		
		public function checkExist($product_code_id, $code){
			$this->db->where('product_code_id', $product_code_id);
			$this->db->where('code', $code);
			$query = $this->db->get("product_detail");
			if($query->num_rows() > 0){
				return true;
			} else{
				return false;
			}
		}
		
		public function add($product_detail){
			$this->db->insert("product_detail", $product_detail);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function update($id, $vi_name, $en_name, $retail_price, $wholesale_price, $code, $category_level_1_id, $category_level_2_id, $category_level_3_id,
					$product_fit_id, $product_crotch_id, $product_code_id, $product_size_id, $description){
			$data = array(
				'vi_name' => $vi_name,
				'en_name' => $en_name,
				'retail_price' => $retail_price,
				'wholesale_price' => $wholesale_price,
				'code' => $code,
				'category_level_1_id' => $category_level_1_id,
				'category_level_2_id' => $category_level_2_id,
				'category_level_3_id' => $category_level_3_id,
				'product_fit_id' => $product_fit_id,
				'product_crotch_id' => $product_crotch_id,
				'product_code_id' => $product_code_id,
				'product_size_id' => $product_size_id,
				'description' => $description
            );
			$this->db->where('id', $id);
			$this->db->update('product_detail', $data);
			return ($this->db->affected_rows() != 1) ? false : true;
		}
		
		public function delete($id){
			$this->db->where('id', $id);
			$this->db->delete('product_detail');
			return ($this->db->affected_rows() != 1) ? false : true;
		}
	}

?>